﻿using System;
using System.Collections.Generic;
using System.Text;
using Common;
using LLFM.CAT.Config;
using System.Data;
using System.Data.SqlClient;
using LLFM.CAT.Model;

namespace LLFM.CAT.Service
{
    public sealed class ProductExtentionService
    {
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="Description"></param>
        /// <param name="FlashUrl"></param>
        /// <param name="Status"></param>
        public static void CreateProductExtention(int productId, string Description, string FlashUrl,
           short Status)
        {
            SqlHelper.ExecuteNonQuery(DBConfig.BitautoSDT
                , CommandType.StoredProcedure
                , "pro_CreateProductExtention"
                , new SqlParameter("@ProductId", productId)
                , new SqlParameter("@Description", Description)
                , new SqlParameter("@FlashUrl", FlashUrl)
                , new SqlParameter("@CreateTime", DateTime.Now)
                , new SqlParameter("@Status", Status)
                , new SqlParameter("@LastUpdateTime", DateTime.Now));
        }

        /// <summary>
        /// 通过producteId获取扩展的信息
        /// </summary>
        /// <param name="productId"></param>
        /// <returns></returns>
        public static M_ProductExtention GetProductExtentionByProductId(int productId)
        {
            DataTable dt = SqlHelper.ExecuteDataset(DBConfig.BitautoSDT
                , CommandType.StoredProcedure
                , "pro_GetProductExtentionByProductId"
                , new SqlParameter("@ProductId", productId)).Tables[0];

            return ModelHelper.FillModel<M_ProductExtention>(dt);
        }

        /// <summary>
        /// 更新Product的扩展表
        /// </summary>
        /// <param name="ProductId"></param>
        /// <param name="Description"></param>
        /// <param name="FlashUrl"></param>
        /// <param name="Status"></param>
        public static void UpdateProductExtention(int ProductId, string Description,
            string FlashUrl, short Status)
        {
            SqlParameter[] parms = {new SqlParameter("@ProductId",ProductId),
                                    new SqlParameter("@Description",Description),
                                    new SqlParameter("@FlashUrl",FlashUrl),
                                    new SqlParameter("@Status",Status),
                                    new SqlParameter("@LastUpdateTime",DateTime.Now)};
            SqlHelper.ExecuteScalar(
                DBConfig.BitautoSDT,
                CommandType.StoredProcedure,
                "pro_UpdateProductExtention",
                parms
                );
        }
    }
}
